#pragma once

#include "TextureAtlas.h"
#include "IntrusiveList.h"


class HWTextureManager;
class CRenderTarget;


class HWTextureAtlas :
	public TextureAtlas
{
public: 
	virtual XUINT32 AddRef();
	virtual XUINT32 Release();
	static HRESULT Create(HWTextureManager * pTextureManager, XUINT32 atlasWidth, XUINT32 atlasHeight, enum PixelFormat pixelFormat, CRenderTarget * pRenderTarget, HWTextureAtlas * * ppHWTextureAtlas);
	static HRESULT CreateStandAlone(HWTextureManager * pTextureManager, const struct XSIZE * pAtlasSize, const struct XRECT_WH * pViewBounds, CRenderTarget * pRenderTarget, XBOOL includePadding, HWTextureAtlas * * ppHWTextureAtlas);
	XBOOL IsEmpty();
	HRESULT EnsureUIThreadSurface(struct IPALOptimizedGraphicsDevice * pUIThreadDevice);
	struct IPALSurface * GetUIThreadSurface();
	void NotifyUpdate();
	void TraceUtilization();
	XBOOL IsLost();
	XBOOL AreResourcesAllocated();
	void MarkAsLost();
	void MarkAsOrphaned();
	static XUINT32 ListEntryOffset();
	HRESULT OfferVideoMemorySurface(struct IPALOptimizedGraphicsDevice * pDevice);
	HRESULT ReclaimVideoMemorySurface(struct IPALOptimizedGraphicsDevice * pDevice, XBOOL * pWasDiscarded);
	void UpdateAtlasSqmData(CCoreServices * pCore);

private: 
	HWTextureAtlas(HWTextureManager * pTextureManager, enum PixelFormat pixelFormat);
	virtual ~HWTextureAtlas();

	HRESULT Init(XUINT32 textureWidth, XUINT32 textureHeight, CRenderTarget * pRenderTarget);
	HRESULT InitStandAlone(const struct XSIZE * pAtlasSize, const struct XRECT_WH * pViewBounds, CRenderTarget * pRenderTarget, XBOOL includePadding);
	struct IPALOptimizedGraphicsDevice * m_pUIThreadDevice;
	struct IPALSurface * m_pUIThreadSurface;
	AtlasNode * m_pWhitePixelView;
	unsigned int m_updatedThisFrame;
	HWTextureManager * m_pTextureManagerNoRef;

	struct IntrusiveList<HWTextureAtlas>::ListEntry m_atlasListEntry;
};